package logic

import (
	"context"
	"go.uber.org/zap"
	"order_srv/internal/dao"
	"smart-health-platforms/pkg"

	"order_srv/internal/svc"
	"order_srv/order"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderReturnLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderReturnLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderReturnLogic {
	return &OrderReturnLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderReturnLogic) OrderReturn(in *order.OrderReturnRequest) (*order.OrderReturnResponse, error) {
	orderReturn, err := dao.OrderReturn(in) //根据订单号获取订单
	if err != nil {
		pkg.Error("订单不存在", zap.Error(err))
		return nil, err
	}
	return &order.OrderReturnResponse{ //根据订单号获取订单
		OrderSn:    orderReturn.OrderSn,
		PayStatus:  uint32(orderReturn.PayStatus),
		TotalPrice: float32(orderReturn.TotalPrice),
		GoodSkuId:  uint32(orderReturn.GoodskuId),
	}, nil
}
